package com.nahan.myphoto.ViewPicture;

import android.app.Dialog;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
import com.nahan.myphoto.R;
import com.nahan.myphoto.ViewPicture.previewlibrary.view.BasePhotoFragment;

/**
 * @time: 2020-9-1 16:16:34
 * Deprecated:
 */

public class UserFragment extends BasePhotoFragment {
    /****用户具体数据模型***/
    private UserViewInfo b;

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        b = (UserViewInfo) getBeanViewInfo();
        imageView.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                Log.d("SmoothImageView","onLongClick");
//                Toast.makeText(getContext(), "长按事件:" + b.getUser(), Toast.LENGTH_LONG).show();
//                BottomSheetDialog dialog=new BottomSheetDialog(getActivity());
//                View dialogView= LayoutInflater.from(getActivity()).inflate(R.layout.view_picture,null);
//                TextView txt_title = (TextView) dialogView.findViewById(R.id.txt_title);
//                TextView txt_cancel = (TextView) dialogView.findViewById(R.id.txt_cancel);
//                txt_title.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View v) {
//                        Glide.with(getActivity()).asBitmap().load(b.getUrl()).into(new SimpleTarget<Bitmap>() {
//                            @Override
//                            public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
//                                ImageDownloadUtil.saveImage(getActivity(), b.getUrl(), resource);
//                            }
//                        });
//                        dialog.dismiss();
//                    }
//                });
//                txt_cancel.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View v) {
//                        dialog.dismiss();
//                    }
//                });
//                dialog.setCancelable(false);
//                dialog.setCanceledOnTouchOutside(true);
//                dialog.setContentView(dialogView);
//                dialog.show();


                if (!imageView.isMoved())
                {
                    View view = LayoutInflater.from(getActivity()).inflate(R.layout.view_picture, null);
                    final Dialog dialog = new Dialog(getActivity(), R.style.BottomDialogStyle);
                    TextView txt_title = (TextView) view.findViewById(R.id.txt_title);
                    TextView txt_cancel = (TextView) view.findViewById(R.id.txt_cancel);
                    txt_title.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            Glide.with(getActivity()).asBitmap().load(b.getUrl()).into(new SimpleTarget<Bitmap>() {
                                @Override
                                public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
                                    ImageDownloadUtil.saveImage(getActivity(), b.getUrl(), resource);
                                }
                            });
                            dialog.dismiss();
                        }
                    });
                    txt_cancel.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            dialog.dismiss();
                        }
                    });
                    Window window = dialog.getWindow();
                    window.setGravity(Gravity.BOTTOM);
                    window.setContentView(view);
                    WindowManager.LayoutParams lp = window.getAttributes();
                    lp.width = WindowManager.LayoutParams.MATCH_PARENT;
                    lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
                    window.getDecorView().setPadding(0, 0, 0, 0);//关键代码
                    window.setAttributes(lp);
                    dialog.show();
                }





                return false;
            }
        });
    }



    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_image_photo_layout, container, false);
    }
}
